package com.example.thread.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Future和FutureTask都可以获取异步线程任务执行情况
 * 前者是一个接口，后者是一个具体实现类，后者通过接口多继承，实现了Future接口和Runnable接口
 */
public class CallableTest {

    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(new MyCallable());
        Thread thread = new Thread(futureTask);
        thread.start();

        try {
            Thread.sleep(1000);
            System.out.println("运行结果:"+futureTask.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("执行完成");
    }
}
